<template>
    <div class="register">
        <el-form class="frosted" label-position="top">
            <el-form-item label="用户名称">
                <el-input v-model="username" placeholder="用户名称" ></el-input>
                
            </el-form-item>
            <el-form-item label="用户邮箱">
                <el-input v-model="email" disabled placeholder="用户邮箱"></el-input>
            </el-form-item>
            <el-form-item label="校验码">
                <el-row>
                    <el-col :span="12"><el-input disabled v-model="email_code" placeholder="邮箱验证码" style=""></el-input></el-col>
                    <el-col :span="12"><el-button disabled type="primary">获取验证码</el-button></el-col>
                </el-row> 
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="user.password" type="password" placeholder="账户密码" ></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
                <el-input v-model="user.ispassword" type="password" placeholder="确认密码" disabled></el-input>
            </el-form-item>
            <el-form-item>
                <el-button class="register_btn" @click="register" type="primary button" >注册</el-button>
            </el-form-item>
            <el-form-item>
                <div class="register-other">
                    <div>
                        <span>已经有账号？</span><a @click="toLogin">去登陆</a>
                    </div> 
                </div>
            </el-form-item>
        </el-form>
    </div>
    
</template>

<script>
import { ElNotification } from 'element-plus'
import {register} from "@/request/api"


export default {
    name:"registe",
    data(){
        return{
            username:"",
            email:"",
            email_code:"",
            invite_code:'',
            user:{
                password:"",
                ispassword:"",                
            }   
        }
    },
    methods:{
        register(){
            register(this.$data.username,this.$data.user.password)
            .then(res=>{
                ElNotification.success({
                    title:"注册成功",
                    message:"欢迎加入",
                    offset:100
                }),
                setTimeout(()=>{
                    this.$router.push("Login")
                },1500)
            })
            .catch(
                err=>{
                    ElNotification.error({
                        title:"注册失败",
                        message:err.response.data,
                        offset:100
                    })
                }
            ) 
        },
        toLogin(){
            this.$router.push("/auth/login")
        },   
    }
}
</script>

<style scoped>
/* 毛玻璃 */
.frosted{
    background: rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-radius: 25px;
    box-shadow:inset 0 0 6px rgba(255, 255, 255, 0.2);
}


.el-form{
    height: 100%;
    border-radius: 25px;
    width: 380px;
    margin: 0 auto;
    text-align: center;
    padding: 10px;
    transform: translateY(20%);

    display: flex;
    flex-direction: column;
    align-items: center;
    
}
/* 修改label颜色 */
:deep(.el-form-item__label){
    color: gainsboro;
}

.el-form-item{
    width: 65%;
}

.el-form .el-input{
    opacity: 0.8;
}
.register_btn{
    margin-top: 10px;
    width: 90%;
    border-radius: 8px;
}

:deep(.el-form-item__content){
    justify-content: center;
}


.register-other{
    width:60%;
    display: flex;
    justify-content: space-between;

    font-size: 14px;
    cursor: pointer;
}
.register-other span{
    color: gainsboro;
    cursor: default;
}

</style>